/**
 * Created by gitbong on 14/12/10.
 */
module.exports = function (grunt) {
    var config = {
        publishPath: 'release/'
    };

    // Grunt 配置
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        clean: {  // Grunt任务开始前的清理工作
            files: [config.publishPath + '*']
        },
        cssmin: {  //CSS文件压缩
            css: {
                files: {
                    'release/css/style.min.css': ['src/css/*']
                }
            }
        },
        concat: {   //js合并
            domop: {
                src: [
                    'src/js/libs/jquery-1.6.2.min.js',
                    'src/js/libs/TweenMax.min.js',
                    'src/js/libs/gbbase.js',
                    'src/js/libs/gbdebug.js',
                    'src/js/app.js'
                ],
                dest: config.publishPath + 'js/libs.js'
            }
        },
        uglify: {   //js压缩
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
            },
            build: {
                src: config.publishPath + 'js/libs.js',
                dest: config.publishPath + 'js/libs.min.js'
            }
        },
        //clean: {  // Grunt任务开始前的清理工作
        //    files: [config.publishPath + 'js/libs.js']
        //},
        copy: {
            main: {
                files: [
                    {expand: true, cwd: 'src/resource', src: '**', dest: config.publishPath + 'resource/'},
                    {expand: true, cwd: 'src/gbtpl', src: '**', dest: config.publishPath + 'gbtpl/'},
                    {expand: true, cwd: 'src', src: '**.html', dest: config.publishPath}
                ]
            }
        },
        usemin: {
            html: [config.publishPath + '*.html'],
            options: {
                assetsDirs: ['build/js']
            }
        }
    });
    // 载入concat和uglify插件，分别对于合并和压缩
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-usemin');
    // 注册任务
    grunt.registerTask('default', ['clean', 'cssmin', 'concat', 'uglify', 'copy', 'usemin']);
    //grunt.registerTask('default', ['copy']);
};